package zju.lzy.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.web.bind.annotation.*;
import zju.lzy.dto.IOTMessage;
import zju.lzy.dto.MessageReq;
import zju.lzy.dto.ResponseMessage;
import zju.lzy.service.message.MessageReceiver;
import zju.lzy.service.message.MessageService;


/**
 * @author lzy
 */
@RestController
public class MessageController {

    private static final Logger logger = LoggerFactory.getLogger(MessageController.class);

    @Autowired
    private MessageService messageService;


    @PostMapping("/queryData")
    ResponseMessage queryDataWithFilter(@RequestBody MessageReq messageReq) {
        logger.info("接收到查询，转换对象:{}，转换sql语句:{}", messageReq, messageReq.generateSql());
        return new ResponseMessage(true, "信息查询成功", messageService.queryMessages(messageReq));
    }

    @GetMapping("/getDataBySender")
    ResponseMessage getDataBySender(Integer sender) {
        return ResponseMessage.success("查询数据成功", messageService.getDataBySender(sender));
    }

}
